using Gateway.Domain.EFCore.Configuration;
using Gateway.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Gateway.Domain.Configuration;

public class MenuApiAuthConfiguration : EntityConfiguration<MenuApiAuth>
{
    public override void Configure(EntityTypeBuilder<MenuApiAuth> builder)
    {
        builder.ToTable(t => t.HasComment("菜单接口权限表"));
        builder.Property(x => x.Code).IsRequired().HasMaxLength(50).HasComment("接口权限标识");
        builder.Property(x => x.Url).IsRequired().HasMaxLength(100).HasComment("接口地址  相对路径  比如 api/setting/role");
        builder.HasOne(x => x.Menu).WithMany(x => x.ApiAuths)
            .HasForeignKey(x => x.MenuId)
            .OnDelete(DeleteBehavior.Cascade);
        base.Configure(builder);
    }
}